// pages/andon_search/deal_error/deal_error.js
var west_line, east_line, ShangY_line, ZhongS_line;
const mybehavior = require("../../../behaviors/requests")
Page({
  behaviors: [mybehavior],
  /**
   * 页面的初始数据
   */
  data: {
    num_flag: true,
    tag_id: '',
    led_location: '',
    location: '',
    line: '',
    material_name: '',
    showLEDPicker: false,
    LED_locationPickerValue: ["1", "2", "3"],
    showLocationPicker: false,
    locationPickerValue: ["西区家用总装", "东区家用总装", "商用总装", "中山基地"],
    showLinePicker: false,
    linePickerValue: [],
    showMaterialPicker: false,
    materialPickerValue: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this;
    this.get('http://logisticsengineering.gree.com/andon_system/get_west_line_list', {}).then(res => {
      west_line = res.data;
    })
    this.get('http://logisticsengineering.gree.com/andon_system/get_east_line_list', {}).then(res => {
      east_line = res.data;
    })
    this.get('http://logisticsengineering.gree.com/andon_system/get_ShangY_line_list', {}).then(res => {
      ShangY_line = res.data;
    })
    this.get('http://logisticsengineering.gree.com/andon_system/get_ZhongS_line_list', {}).then(res => {
      ZhongS_line = res.data;
    })
  },
  show_led() {
    this.setData({
      showLEDPicker: true
    })
  },
  cancel_led() {
    this.setData({
      showLEDPicker: false
    })
  },
  show_location() {
    this.setData({
      showLocationPicker: true
    })
  },
  cancel_location() {
    this.setData({
      showLocationPicker: false
    })
  },
  show_line() {
    this.setData({
      showLinePicker: true
    })
  },
  cancel_line() {
    this.setData({
      showLinePicker: false
    })
  },
  show_material_name() {
    this.setData({
      showMaterialPicker: true
    })
  },
  cancel_material_name() {
    this.setData({
      showMaterialPicker: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  onSubmit_num() {
    let that = this;
    this.get('http://logisticsengineering.gree.com/andon_system/closed_loop_num', {
      data: {
        tag_id: that.data.tag_id,
        led_location: that.data.led_location
      },
    }).then(res => {
      if (res.code == 20000) {
        wx.showToast({
          title: '已成功发出灭灯指令',
        })
      }
    })
  },
  onSubmit_work(values) {
    let that = this;
    this.get('http://logisticsengineering.gree.com/andon_system/closed_loop_work', {
      data: {
        location: that.data.location,
        line: that.data.line,
        material_name: that.data.material_name
      },
    }).then(res => {
      if (res.code == 20000) {
        wx.showToast({
          title: '已成功发出灭灯指令',
        })
      }
    })
  },
  LED_onConfirm(ev) {
    const {
      value
    } = ev.detail;
    this.setData({
      led_location: value,
      showLEDPicker: false
    })
  },
  Location_onConfirm(ev) {
    const {
      value
    } = ev.detail;
    if (value == "西区家用总装") {
      this.setData({
        linePickerValue: west_line,
        location: value
      })
    } else if (value == "东区家用总装") {
      this.setData({
        linePickerValue: east_line,
        location: value
      })
    } else if (value == "商用总装") {
      this.setData({
        linePickerValue: ShangY_line,
        location: value
      })
      this.linePickerValue = ShangY_line
    } else if (value == "中山基地") {
      this.setData({
        linePickerValue: ZhongS_line,
        location: value
      })
    } else {
      this.setData({
        location: value,
        linePickerValue: []
      })
    }
    this.setData({
      line: '',
      material_name: '',
      materialPickerValue: [],
      showLocationPicker: false
    })
  },
  Line_onConfirm(ev) {
    let that = this;
    const {
      value
    } = ev.detail;
    this.get('http://logisticsengineering.gree.com/andon_system/get_material_list', {
      location: value,
      token: wx.getStorageSync('andon_token')
    }).then(res => {
      if (res.data.code == 20000) {
        console.log(res.data);
        that.setData({
          line: value,
          materialPickerValue: res.data.data,
          material_name: "",
          showLinePicker: false
        })
      } else {
        wx.showToast({
          title: '权限不足',
          icon: "error"
        })
      }
    })

  },
  set_num_flag_true() {
    this.setData({
      num_flag: true
    })
  },
  set_num_flag_flase() {
    this.setData({
      num_flag: false
    })
  },
  Material_onConfirm(ev) {
    const {
      value
    } = ev.detail;
    this.setData({
      material_name: value,
      showMaterialPicker: false
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})